#!/usr/bin/python
# -*- coding: utf-8 -*-

class DisplacementConstraint:

    def __init__ (self, axis, value, growth = 'positive'):

        self._axis = axis
        self._value = value
        self._growth = growth

    def evaluate (self, v):

        if (self._value == None) or (self._growth == None):
            return 1.0

        try:
            if self._growth == 'positive':
                if v > 0.0 and v >= self._value:
                    return 1.0
                else:
                    return 0.0

            else:
                if v < 0.0 and v <= self._value:
                    return 1.0
                else:
                    return 0.0

        # No constraint was defined (None value).
        except TypeError:
            return 1.0

    def __str__ (self):

        return '[Axis: ' + self._axis + ' Growth: ' + str(self._growth) + ' Value: ' + str(self._value) + ']'
